package com.mc.lp.database.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.mc.lp.database.entity.type.BloodGroupType;
import com.mc.lp.database.entity.type.GenderType;

@Entity
@Table(name = "T_ENTITY")
public class MicroCampusEntity extends MicroCampusBaseEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="REGISTRATION_ID")
	private RegistrationEntity registration;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="USER_ID")
	private UserEntity user;

	@Column(name = "ENTITY_TYPE_ID")
	private Integer entityType;

	@Column(name = "FIRST_NAME")
	private String firstName;

	@Column(name = "LAST_NAME")
	private String lastName;

	@Column(name = "MOTHER_FIRST_NAME")
	private String motherFirstName;

	@Column(name = "MOTHER_LAST_NAME")
	private String motherLastName;

	@Column(name = "DOB")
	private Date dob;
	
	@Column(name = "PRIMARY_EMAIL")
	private String primaryEmail;
	
	@Column(name = "SECONDARY_EMAIL")
	private String secondaryEmail;
	
	
	@Column(name = "GENDER")
	@Enumerated(EnumType.ORDINAL)
	private GenderType gender;

	@Column(name = "BLOOD_GROUP")
	private BloodGroupType bloodGroup;

	@Column(name = "IS_ACTIVE")
	private Boolean isActive;

	@Column(name = "IS_DELETED")
	private Boolean isDeleted;

	@Column(name = "SCHOOL_BRANCH_ID")
	private Long schoolBranch;
	
	@Column(name = "PARENT_ENTITY_ID")
	private Long parentEntityId;

	@OneToMany(mappedBy= "entityId",fetch=FetchType.LAZY, cascade= CascadeType.ALL)
	private Set<AttachmentEntity> attachments; 
	
	// AP Have to FIX Fetch Type for address and contacts on Query Level to Eager.
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="address_id")
	private AddressEntity address;
	
	@OneToMany(mappedBy= "entity",fetch=FetchType.EAGER ,cascade=CascadeType.ALL)
	private Set<ContactEntity> contacts;
	
	
	// As of now can't Make gradeMapping as LAZY as it would have huge impact on code
	@OneToMany(mappedBy= "entity",fetch=FetchType.EAGER ,cascade=CascadeType.ALL, orphanRemoval=true)
	@OrderBy("id DESC")
	private Set<GradeYearMapperEntity> gradeYearMapper;
	
	public Set<GradeYearMapperEntity> getGradeYearMapper() {
		return gradeYearMapper;
	}

	public void setGradeYearMapper(Set<GradeYearMapperEntity> gradeYearMapper) {
		this.gradeYearMapper = gradeYearMapper;
	}

	public Set<AttachmentEntity> getAttachments() {
		return attachments;
	}

	public void setAttachments(Set<AttachmentEntity> attachments) {
		this.attachments = attachments;
	}

	public RegistrationEntity getRegistration() {
		return registration;
	}

	public void setRegistration(RegistrationEntity registration) {
		this.registration = registration;
	}

	public UserEntity getUser() {
		return user;
	}

	public void setUser(UserEntity user) {
		this.user = user;
	}

	public Integer getEntityType() {
		return entityType;
	}

	public void setEntityType(Integer entityType) {
		this.entityType = entityType;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getMotherFirstName() {
		return motherFirstName;
	}

	public void setMotherFirstName(String motherFirstName) {
		this.motherFirstName = motherFirstName;
	}

	public String getMotherLastName() {
		return motherLastName;
	}

	public void setMotherLastName(String motherLastName) {
		this.motherLastName = motherLastName;
	}

	public Date getDob() {
		return dob;
	}

	public void setDob(Date dob) {
		this.dob = dob;
	}

	public GenderType getGender() {
		return gender;
	}

	public void setGender(GenderType gender) {
		this.gender = gender;
	}

	public BloodGroupType getBloodGroup() {
		return bloodGroup;
	}

	public void setBloodGroup(BloodGroupType bloodGroup) {
		this.bloodGroup = bloodGroup;
	}

	public Boolean getIsActive() {
		return isActive;
	}

	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}

	public Boolean getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(Boolean isDeleted) {
		this.isDeleted = isDeleted;
	}

		public Long getSchoolBranch() {
		return schoolBranch;
	}

	public void setSchoolBranch(Long schoolBranch) {
		this.schoolBranch = schoolBranch;
	}

	public Long getParentEntityId() {
		return parentEntityId;
	}

	public void setParentEntityId(Long parentEntityId) {
		this.parentEntityId = parentEntityId;
	}

	public AddressEntity getAddress() {
		return address;
	}

	public void setAddress(AddressEntity address) {
		this.address = address;
	}

	public Set<ContactEntity> getContacts() {
		return contacts;
	}

	public void setContacts(Set<ContactEntity> contacts) {
		this.contacts = contacts;
	}

	public String getPrimaryEmail() {
		return primaryEmail;
	}

	public void setPrimaryEmail(String primaryEmail) {
		this.primaryEmail = primaryEmail;
	}

	public String getSecondaryEmail() {
		return secondaryEmail;
	}

	public void setSecondaryEmail(String secondaryEmail) {
		this.secondaryEmail = secondaryEmail;
	}
}
